﻿using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.HttpOverrides;

namespace DoNet.Extensions.Setups
{
    /// <summary>
    /// 解决 Nginx 代理不能获取IP问题
    /// </summary>
    public static class ForwardedSetup
    {
        /// <summary>
        /// 解决 Nginx 代理不能获取IP问题
        /// </summary>
        /// <param name="app"></param>
        /// <returns></returns>
        public static IApplicationBuilder UseForwardedSetup(this IApplicationBuilder app)
        {
            return app.UseForwardedHeaders(new ForwardedHeadersOptions
            {
                ForwardedHeaders = ForwardedHeaders.XForwardedFor | ForwardedHeaders.XForwardedProto
            });
        }
    }
}
